exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = class extends think.BaseController {

    /**
     * 下载通讯录模板
     * @param {String} table_name          表名
     * @returns
     */
    downloadModelAction() {
        var _this = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            let table_name = _this.post('table_name');
            const excelService = _this.service('excel/ExcelService');
            const res = yield excelService.downloadModel(table_name);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this.json(aj);
        })();
    }

    /**
     * 下载通讯录
     * @param {String} table_name          表名
     * @returns
     */
    downloadExcelAction() {
        var _this2 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            let table_name = _this2.post('table_name');
            const excelService = _this2.service('excel/ExcelService');
            const res = yield excelService.downloadExcel(table_name);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this2.json(aj);
        })();
    }
    /**
     * 上传通讯录
     * @param {String} table_name          表名
     * @param {String} data_arr          excel数据数组
     * @param {String} ass_table_obj       模板表对象
     * @returns
     */
    uploadExcelAction() {
        var _this3 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            let table_name = _this3.post('table_name');
            let data_arr = _this3.post('data_arr');
            let association_obj = _this3.post('association_obj');
            let user = _this3.getUser();
            const excelService = _this3.service('excel/ExcelService');
            const res = yield excelService.uploadExcel(table_name, data_arr, association_obj, user);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this3.json(aj);
        })();
    }

    /**
     * excel树
     * @param {String} table_name          表名
     * @returns
     */
    excelTreeListAction() {
        var _this4 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            let table_name = _this4.post('table_name');
            const excelService = _this4.service('excel/ExcelService');
            const res = yield excelService.excelTreeList(table_name);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this4.json(aj);
        })();
    }
};

//
// get_exporttablelist:function (req, res) {
//     var pages = req.query;
//     excelService.exportTableList(pages,function(data){
//         res.send(data);
//     })
// },
// post_findexporttablelist:function (req, res) {
//     var pages = req.body;
//     excelService.findExportTableList(pages,function(data){
//         res.send(data);
//     })
// },
// post_addorupdateexcel:function (req, res) {
//     var obj = req.body;
//     if ('id' in obj) {
//         CrudService.update(db['sys_excel'], obj, function (ret) {
//             res.send(ret);
//         });
//     } else {
//         CrudService.save(db['sys_excel'], obj, function (ret) {
//             res.send(ret);
//         });
//     }
//
//
// },
// /**
//  * 单条删除和批量删除
//  */
// post_deleteexcel:function (req, res) {
//     var obj = req.body;
//     if ('ids' in obj) {
//         var ids = obj.ids;
//         var msgStauts = [];
//         for (var i = 0; i < ids.length; i++) {
//             var id = ids[i];
//             CrudService.delete(db['sys_excel'], id, function (ret) {
//                 if (ret.status === false) {
//                     msgStauts.push(i);
//                 }
//             });
//         }
//         if (msgStauts.length == 0) {
//             res.send({status: true, msg: '删除成功'});
//         } else {
//             res.send({status: false, msg: '有' + msgStauts.length + '条数据删除失败'});
//         }
//
//
//     } else {
//         var id = obj.id;
//         CrudService.delete(db['sys_excel'], id, function (ret) {
//             res.send(ret);
//         });
//
//     }
//
//
// },
// //excel树
//
// get_getexceltreelist: function (req, res) {
//     excelService.getExcelTreeList(req.query,function (ret) {
//         res.send(ret.result);
//     })
// }